<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
require_once('../../lib/libtablas.php.inc');
verificar_inicio_sesion();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/sybmasstyle.css">
<script src="<?php echo LAYOUT_URI?>/jquery-1.2.1.min.js"
	type="text/javascript"></script>
<script src="<?php echo LAYOUT_URI?>/menu-collapsed.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/style.css" >
<link rel="stylesheet" type="text/css"
	href="<?php echo JAVASCRIPT_URI?>/tabs/tabs.css">
<script src="<?php echo JAVASCRIPT_URI?>/tabs/tabs.js"
	type="text/javascript"></script>
<script type="text/javascript" src="<?php echo JAVASCRIPT_URI?>/commons.js">></script>
<script src="<?php echo JAVASCRIPT_URI?>/validacionFormularios.js"
	type="text/javascript"></script>

<title>.:: Sybmas - Definicion de restricciones</title>
<!--[if lt IE 8]>
   <style type="text/css">
   li a {display:inline-block;}
   li a {display:block;}
   </style>
   <![endif]-->
</head>
<body>
<script src="<?php echo JAVASCRIPT_URI?>/tooltip/wz_tooltip.js"
	type="text/javascript"></script>
<div id="dialog">


<div class="title">Agregar llave primaria/unica</div>

<form action="pkunique2.php" method="post" target="constraints_dialog">
<?php 
$dbname=false;
foreach($_GET as $key => $value){
	$$key=$value;
	echo "<input type='hidden' name='$key' value='$value'>\n";
}
?>
<h2>Seleccione los campos que formaran la <?php echo $constraintType=='pk'?'llave primaria':'restriccion de unicidad'?></h2>
<?php
$cambio_bd_exitoso=true;
$sybuser_connection=start_default_sybuser_connection();
if($dbname){
	$cambio_bd_exitoso=sybase_select_db($dbname,$sybuser_connection);
}

if($cambio_bd_exitoso){
	$query="SELECT c.colid,c.name,t.name AS type,c.length,c.prec,c.scale ".		
		"FROM syscolumns c, systypes t ".
		"WHERE c.id=$id ".
		"AND c.usertype*=t.usertype";
	$result=@sybase_query($query,$sybuser_connection);
	$cname="{$constraintType}_{$tablename}_".substr(time(),-4);	
?>
<table width="100%" border="1">
	<caption>Columnas</caption>
	<tbody>
		<tr>
			<td colspan="4">
				<table>
					<tr>
						<th>Nombre: </th>
						<td><input type="text" name="cname" value="<?php echo $cname?>"
						onkeydown="return onKeyPressPermiteAlfaNumericosNoEspacios(event)"
						maxlength="30"
						></td>						
					</tr>
				</table>			
			</td>
		</tr>
		
		<tr>
			<th>colid</th>
			<th>nombre</th>
			<th>tipo</th>
			<td>
				<img onmouseover="Tip('Active los checkbox para seleccionar una columna')" 
					onmouseout="UnTip()" src="<?php echo IMG_URI?>/help.png">
			</td>
		</tr>
<?php 
	while($data=sybase_fetch_array($result)){
			$name=$data['name'];
			$type=$data['type'];
			$length=$data['length'];
			$prec=$data['prec'];
			$scale=$data['scale'];
			
			if(isset($prec) && isset($scale)){
				$type.="($prec,$scale)";				
			}else if(isset($length)){
				$type.="($length)";
			}
?>
		<tr>
			<td><?php echo $data['colid']?></td>
			<td><?php echo $data['name']?></td>
			<td><?php echo $type?></td>
			<td><input type="checkbox" name="columns[]" value="<?php echo $data['name']?>"></td>
		</tr>
<?php 
	}
?>
	</tbody>
</table>
<?php 
}//if($cambio_bd_exitoso)
//Cerrando conexiones a la base de datos
sybase_close($sybuser_connection);
?>
<hr>
<input type="submit" value="Continuar">
<input type="button" value="Cancelar" onclick="window.close()">
</form>
</div>
</body>
</html>